package wangwenjun.phase2.concurrencypattern.eventrouter.demo01;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import util.ThreadUtil;
import wangwenjun.phase2.concurrencypattern.eventrouter.demo01.framework.Event;
import wangwenjun.phase2.concurrencypattern.eventrouter.demo01.framework.Router;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author ChangLiang
 * @date 2020/6/20
 */
public class AppTest {

    @Test
    @DisplayName("test")
    public void test() throws InterruptedException {
        Router router = new Router();
        new Thread(()->{
            while (true) {
                router.addEvent(new Event("A", "AAAbbbCCC"));
                ThreadUtil.sleepForMilliSeconds(ThreadLocalRandom.current().nextInt(200,1000));
            }
        }
        ,"eventA-producer-thread").start();

        new Thread(()->{
            while (true) {
                router.addEvent(new Event("B", "AAAbbbCCC"));
                ThreadUtil.sleepForMilliSeconds(ThreadLocalRandom.current().nextInt(200,1000));
            }
        }
                ,"eventA-producer-thread").start();

        ThreadUtil.sleepForMilliSeconds(100);

        Thread.currentThread().join();
    }
}
